// 导入路由管理包
import { Router, Route, Switch, Redirect } from 'react-router-dom';
// 导入自定义history
import { customHistory } from './utils/history';
// 导入页面(组件)
import { Login } from '@/pages/Login/Login';
import { Layout } from '@/pages/Layout/Layout';
import { ProfileEdit } from './pages/Edit/ProfileEdit';
import { Article } from './pages/Article/Article';
// import HOC from './pages/HOC/App';
import App2 from './pages/HOC2/App2';
import { isAuth } from './utils/token';

import './App.scss';

function App() {
  const authRoute = () => {
    // 判断用户是否登录
    const isLogin = isAuth();
    if (isLogin) {
      return <ProfileEdit />;
    } else {
      // 重定向到登录也
      return (
        <Redirect
          to={{
            pathname: '/login',
            state: {
              from: customHistory.location.pathname,
            },
          }}
        />
      );
    }
  };

  return (
    <Router history={customHistory}>
      <div className="app">
        <Switch>
          <Route exact path={'/'} render={() => <Redirect to={'/layout'} />} />
          <Route path={'/layout'} component={Layout} />
          <Route path={'/login'} component={Login} />
          <Route path={'/articles/:id'} component={Article} />
          <Route path={'/edit/user'} component={ProfileEdit} />
          {/* <Route path={'/hoc'} component={HOC} /> */}
          <Route path={'/hoc2'} component={App2} />
          {/* <Route path={'/edit/user'} render={authRoute} /> */}
        </Switch>
      </div>
    </Router>
  );
}

export default App;
